
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>基金设置</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!--导入layui相关的样式-->
    <script src="../jQuery/jquery-1.11.2.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
    <script src="../layui/layui.js"></script>
    <script type="text/javascript" src="/js/verify/verifyJs.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/font.css">
</head>
<body>
<blockquote class="layui-elem-quote news_search">
<!-- 多条件查询层开始 注意：要与数据表格放在一起-->
<script type="text/html"  id="fund_search">
    <div style="float: left">
        <form class="layui-form layui-col-md12 x-so"  id="fund_searchs" >
            基金名称:
            <div class="layui-input-inline">
                <input type="text" name="fundName" id="fundName"
                       placeholder="请输入基金名称" autocomplete="off" class="layui-input">
            </div>
            基金类型:
            <div class="layui-input-inline" >
                <select name="fundType" class="layui-inline">
                    <option value="">---请选择---</option>
                    <option value="1">封闭式</option>
                    <option value="2">开放式</option>
                </select>
            </div>
            <button id="search" class="layui-btn layui-btn-primary" lay-submit data-type="reload"
                    lay-filter="provinceSearch">
                <i class="layui-icon layui-icon-search"></i>
            </button>
        </form>
    </div>
        <!-- 表格头部上方工具栏 -->
        <div class="layui-btn-container layui-input-inline" style="padding-left: 150px">
            <button class="layui-btn layui-btn-danger" lay-event="batchDel"><i class="layui-icon">&#xe640;</i>批量删除</button>
            <button class="layui-btn  layui-btn-normal" lay-event="add"><i class="layui-icon">&#xe654;</i>添加</button>
        </div>
</script>
<!-- 多条件查询层结束 -->
<!--数据表格-->
<table class="layui-hide" id="fundTable" lay-filter="fundList"></table>
<!-- 行中操作按钮[仅对本行操作] -->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-normal layui-icon layui-icon-edit" lay-event="update">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-icon layui-icon-delete" lay-event="delete">删除</a>
</script>

<!-- 添加/修改界面开始 -->
<div id="data-main" style="display: none;">
    <div style="margin-left: 120px;margin-top: 30px">
        <form class="layui-form" id="seatForm" method="post" lay-skin="line" lay-filter="seatFormTest">
            <div class="layui-form-item">
                <div class="layui-inline">
                <label class="layui-form-label" >基金代码</label>
                <div class="layui-input-inline" >
                    <input name="fundId" lay-verify="required" onblur="inputVerify(value,6,this)" placeholder="请输入基金代码" autocomplete="off" class="layui-input"/>
                </div>
                </div>
                <div class="layui-inline">
                <label class="layui-form-label">基金名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="fundName" lay-verify="required" placeholder="请输入基金名称" autocomplete="off" class="layui-input"/>
                </div>
                </div>
           <!-- <div class="layui-form-item">
                <label class="layui-form-label" style="width: 250px;right: 170px;top: -40px">基金管理公司</label>
                <div class="layui-input-inline" style="right: 170px;top: -40px">
                    <input type="text" name="adminId" lay-verify="required" placeholder="请输入基金管理人" autocomplete="off" class="layui-input"/>
                </div>
            </div>-->
                <div class="layui-inline">
                <label class="layui-form-label" id="ssss">管理公司</label>
                <div class="layui-input-inline">
                    <select  name="adminId" id="ms" >
                        <option value="">请选择</option>
                    </select>
                </div>
                </div>
            </div>
    <div class="layui-form-item">
        <div class="layui-inline">
                <label class="layui-form-label" id="sss">托管公司</label>
                <div class="layui-input-inline">
                    <select  name="custoId" id="ts" >
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
           <!-- <div class="layui-form-item">
                <label class="layui-form-label" style="width: 250px;right: -180px;top: -90px">基金托管公司</label>
                <div class="layui-input-inline" style="right: -180px;top: -90px">
                    <input type="text" name="custoId" lay-verify="required" placeholder="请输入基金托管人" autocomplete="off" class="layui-input"/>
                </div>
            </div>-->
            <!--<div class="layui-form-item">
                <label class="layui-form-label" style="width: 250px;right: 170px;top: -90px">基金类型</label>
                <div class="layui-input-inline" style="right: 170px;top: -90px">
                    <input type="text" name="fundType" lay-verify="required" placeholder="请输入基金类型" autocomplete="off" class="layui-input"/>
                </div>
            </div>-->
            <div class="layui-inline">
                <label class="layui-form-label" >基金类型</label>
                <div class="layui-input-inline" >
                    <select name="fundType" class="layui-inline">
                        <option value="">---请选择---</option>
                        <option value="1">封闭式</option>
                        <option value="2">开放式</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" >计算天数</label>
                <div class="layui-input-inline" >
                    <input type="text" name="day" lay-verify="required" placeholder="请输入计算天数" autocomplete="off" class="layui-input"/>
                </div>
            </div>
        </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                <label class="layui-form-label" >成立时间</label>
                <div class="layui-input-inline" >
                    <input type="date" name="fundTime" lay-verify="required" placeholder="请输入基金成立时间" autocomplete="off" class="layui-input"/>
                </div>
                </div>
                <!--<div class="layui-inline">
                    <label class="layui-form-label layui-icon">基金成立时间</label>
                    <div class="layui-input-inline">
                        <input type="date" name="dates" lay-verify="required" placeholder="请输入交易日期" autocomplete="off"
                               class="layui-input form-control layer-date">
                    </div>
                </div>-->
                <div class="layui-inline">
                <label class="layui-form-label" >初始净值</label>
                <div class="layui-input-inline" >
                    <input type="text" name="nif" lay-verify="required" placeholder="请输入初始基金净值" autocomplete="off" class="layui-input"/>
                </div>
                </div>

                <div class="layui-inline">
                <label class="layui-form-label" >基金规模</label>
                <div class="layui-input-inline" >
                    <input type="text" name="fundSize" lay-verify="required" placeholder="请输入初始基金规模" autocomplete="off" class="layui-input"/>
                </div>
                </div>
            </div>
            <div  class="layui-form-item" lay-filter="zw">
                <div class="layui-inline">
                <label class="layui-form-label" id="ss">银行卡号</label>
                <div class="layui-input-inline" >
                    <select  name="caId" id="roleId" >
                        <option value="">请选择</option>
                    </select>
                </div>
                </div>
                <div class="layui-inline">
                <label class="layui-form-label" >备注</label>
                <div class="layui-input-inline" >
                    <input type="text" name="notes" placeholder="请输入备注" autocomplete="off" class="layui-input"/>
                </div>
                </div>
            </div>
            <div class="layui-form-item" >
                <div class="layui-col-md4 layui-col-md-offset4" >
                    <button class="layui-btn" lay-submit lay-filter="formSave">保存</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</div>
<!-- 添加/修改界面结束 -->
<!--脚本代码-->
<script type="text/javascript">
    layui.use(['table','layer','form','laypage','util','jquery'],function () {
        //导入模块并得到模块对象
        var table = layui.table,//表格对象
            layer = layui.layer,//弹层对象
            form = layui.form,//表单对象
            laypage = layui.laypage,//分页组件
            $ = layui.jquery,//jquery对象
            util = layui.util;//工具对象
        var method="";
        var ms="";
        var ts="";
        var shuj="";
        var kko="";
        //渲染表格对象
        table.render({
            elem: "#fundTable",//表格对象
            url: "/foundcrud/fund",//后台服务路径
            method: "get",//提交方式
            cellMinWidth: 80,
            height:740,
            toolbar: "#fund_search",//表格上方普通工具栏
            //一页显示5条数据
            limit: 15,
            cols: [
                [
                    {checkbox: true},//开启多选框
                    {field: "fundId", title: "基金代码", align: "center",width:160},
                    {field: "fundName", title: "基金名称", align: "center",width:160},
                    {field: "comName",title: "基金管理公司",align: "center",width:160,width:160,templet :function(d){
                            for (var i=0;i<ms.length;i++){
                                if(d.adminId == ms[i].adminId){
                                    return ms[i].comName;
                                }
                            }
                        }},
                    {field: "company", title: "托管公司", align: "center",width:160,width:160,templet :function(d){
                            for (var i=0;i<ts.length;i++){
                                if(d.custoId == ts[i].custoId){
                                    return ts[i].company;
                                }
                            }
                        }},
                    {field: "fundType",title: "基金类型",align: "center",width:160,templet:function(d){
                            if (d.fundType==1){
                                return "封闭式";
                            }else return "开放式";
                        }},
                    {field: "fundSize", title: "基金规模(元)", align: "center",width:160,templet:function (d) {
                            if (d.fundSize.toString().indexOf(".")!=-1){
                                return d.fundSize.toLocaleString();
                            }else{
                                return (d.fundSize+ '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g,'$1,')+".00";
                            }
                        }},
                    {field: "day",title: "计算天数",align: "center",width:160},
                    {field: "fundTime", title: "成立时间", align: "center",width:160},
                    {field: "nif",title: "初始基金净值(元)",align: "center",width:160},
                    {field: "caId", title: "现金账户名称", align: "center",width:160,templet :function(d){
                            for (var i=0;i<shuj.length;i++){
                                if(d.caId == shuj[i].caId){
                                    return '<span>'+shuj[i].accName+'</span>';
                                }
                            }
                        }},
                    {field: "notes", title: "备注", align: "center",width:160},
                    {fixed:"right",title:"操作",width:160,align:"center",toolbar:"#barDemo",width:160}
                ]
            ],
            page: true,
            //一页选择显示5或10条数据
            limits: [5, 10,20,30,50],
            parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                shuj=res.ca;
                kko+="<option value=''>--请选择--</option>";
                for (var i=0;i<shuj.length;i++){
                    kko+="<option value='"+shuj[i].caId+"'>"+shuj[i].accName+"</option>";
                }
                ms=res.ms;
                ts=res.ts;
                var jj="";
                var kk="";
                jj+="<option value=''>--请选择--</option>";
                for (var i=0;i<ms.length;i++){
                    jj+="<option value='"+ms[i].adminId+"'>"+ms[i].comName+"</option>";
                }
                kk+="<option value=''>--请选择--</option>";
                for (var i=0;i<ts.length;i++){
                    kk+="<option value='"+ts[i].custoId+"'>"+ts[i].company+"</option>";
                }
                $("#roleId").html(kko);
                $("#ms").html(jj);
                $("#ts").html(kk);
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": res.data //解析数据列表
                }}
        });

        //监听添加或修改的提交操作
        //定义请求方式
        form.on('submit(formSave)',function (data) {
            //ajax提交数据
            $.ajax({
                type:method,//提交方式
                url:"/foundcrud/fund",//后台控制器路径
                data:JSON.stringify(data.field),
                dataType:"text",
                contentType:"application/json;charset=utf-8",
                success:function (msg) {
                    layer.closeAll();
                    layer.msg(msg);
                    table.reload("fundTable");
                }
            });
            return false;
        });

        //表格头部工具栏事件代码，根据lay-event属性值判断执行相应的代码
        table.on('toolbar(fundList)', function(obj) {
            //检查表格选择操作状态
            var checkStatus = table.checkStatus(obj.config.id);
            //判断事件event值
            switch(obj.event) {
                //批量删除操作：删除选定的多行数据
                case "batchDel":
                    //获得选中的表格行
                    var data = checkStatus.data;
                    //判断是否大于0行
                    if(data.length>0){
                        layer.confirm('请确认是否真的删除?', function(index){
                            //获取所有选择的id
                            var empNoStr="";

                            for (var i = 0; i < data.length; i++) {
                                empNoStr = empNoStr+data[i].fundId+",";//累加字符
                            }
                            empNoStr=empNoStr.substring(0,empNoStr.length-1);
                            layer.close(index);
                            //使用ajax删除选中的
                            $.ajax({
                                type: "delete",//提交方式为post
                                url: "/foundcrud/fund/"+empNoStr,//后台Servlet路径
                                success: function(msg){
                                    layer.msg('删除成功');
                                    //重新加载表格数据
                                    table.reload('fundList');
                                }
                            });
                        });
                    }else{
                        //没有选择数据行
                        layer.msg('你至少选一行！');
                    }
                    break;
                case 'add':
                    //请求方式为post
                    method="post";
                    //清空表单
                    $("#seatForm")[0].reset();
                    layer.open({
                        type:1,//外部页面为2，内部层1
                        title:"添加基金",
                        area:["80%","60%"],
                        shade:0.4,
                        anim: 1,
                        skin: 'layui-layer-lan',
                        content:$("#data-main").html()
                    });
                    //将主键设置成允许修改[防止因先修改，后增加时，该字段被设置为只读]
                    $("input[name='fundId']").prop("readonly",false);
                    break;
            }
        });

        //监听表格行工具(操作)事件
        table.on("tool(fundList)",function (obj) {
            //得到表格行数据
            var data=obj.data;
            //判断事件event值，与lay-event属性比较(使用switch或if梯形结构都可以,前面已经用过switch,此处使用if梯形结构)
            //判断是否为行修改操作
            if(obj.event == "update"){
                //将设置请求方式为put
                method="put";
                //设置界面信息
                layer.open({
                    type: 1,
                    title:"<span style='color:white' ><i class='layui-icon'>&#xe6b2;</i>基金设置</span>",
                    area: ["80%","60%"],
                    shade: 0.4,
                    content: $("#data-main").html(),
                    skin: 'layui-layer-lan',
                    anim: 1,
                });
                //将当前行数据显示在表单各字段中
                form.val("seatFormTest", {
                    "fundId": data.fundId,
                    "fundName":data.fundName,
                    "adminId":data.adminId,
                    "custoId":data.custoId,
                    "fundType":data.fundType,
                    "fundSize":data.fundSize,
                    "day":data.day,
                    "fundTime":data.fundTime,
                    "nif":data.nif,
                    "caId":data.caId,
                    "notes":data.notes,
                    "right":data.right
                });
                //将主键设置成只读:不允许修改
                $("input[name='fundId']").prop("readonly","readonly");
            }else if(obj.event == "delete"){//判断是否为行删除操作
                layer.confirm("真的删除基金编号为"+data.fundId+"这行数据吗?", function(index){
                    //执行表格中删除操作
                    obj.del();
                    layer.close(index);
                    $.ajax({
                        type: "delete",
                        url: "/foundcrud/fund/"+data.fundId,//后台Servlet路径
                        success: function(msg){
                            //重新加载表格数据
                            table.reload('fundTable');
                            layer.msg(msg);
                        }
                    });
                });
            }

        });
        //多条件搜索

        //搜索表单中提交按钮的事件代码
        form.on("submit(provinceSearch)",function (data) {
            //定义表单数据对象
            var formData=data.field;
            //得到表单数据json字符串
            var json=JSON.stringify(data.field);
            //alert(json);
            //重新加载表格对象
            table.reload("fundTable",{
                //页码
                page:{
                    curr:1
                },
                //条件数据，会带到后台
                where:{
                    fundName: formData.fundName,
                    fundType: formData.fundType
                }
            });
            return false;
        });
    });

</script>
</blockquote>
</body>
</html>
